package com.firesyde.gwt.persistence.guice.bdb;

import com.google.inject.Provider;
import com.sleepycat.bind.serial.ClassCatalog;
import com.sleepycat.bind.serial.StoredClassCatalog;
import com.sleepycat.je.Database;
import com.sleepycat.je.DatabaseException;

/**
 * Simple provider for class catalogs. At the moment it creates a new DB instance every time.
 * @author dan
 *
 */
public class ClassCatalogProvider implements Provider<ClassCatalog> {

	private Provider<Database> dbProvider;

	public ClassCatalogProvider(Provider<Database> dbProvider) {
		this.dbProvider = dbProvider;
	}

	public ClassCatalog get() {
		StoredClassCatalog classCatalog;
		try {
			classCatalog = new StoredClassCatalog(dbProvider.get());
			return classCatalog;
		} catch (Exception e) {
			System.out.println("Error creating class catalog: "+e.getMessage());
			e.printStackTrace();
		}
		return null;
	}

}
